//package com.example.demo.Controller;
//
//import com.alibaba.nacos.api.exception.NacosException;
//import com.alibaba.nacos.api.naming.NamingFactory;
//import com.alibaba.nacos.api.naming.NamingService;
//import org.springframework.cloud.client.ServiceInstance;
//import org.springframework.cloud.client.discovery.DiscoveryClient;
//import org.springframework.context.ConfigurableApplicationContext;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.client.RestTemplate;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@RestController
//@RequestMapping("config")
//public class NacosConfigController {
//
//    private final ConfigurableApplicationContext applicationContext;
//
//    private final RestTemplate RestTemplate;
//
//    private final DiscoveryClient DiscoveryClient;
//
//    public NacosConfigController(ConfigurableApplicationContext applicationContext, RestTemplate RestTemplate, DiscoveryClient discoveryClient) {
//        this.applicationContext = applicationContext;
//        this.RestTemplate = RestTemplate;
//        this.DiscoveryClient = discoveryClient;
//    }
//
//    @GetMapping("")
//    public String GetConfig(){
//        String test = applicationContext.getEnvironment().getProperty("test1");
//        String test2 = applicationContext.getEnvironment().getProperty("test2");
//        String test3 = applicationContext.getEnvironment().getProperty("test3");
//        String test4 = applicationContext.getEnvironment().getProperty("test4");
//        String age = applicationContext.getEnvironment().getProperty("age");
//        return  test + test2 + test3 + test4 + "年龄：" + age;
//    }
//
//    @GetMapping("service")
//    public String GetService(){
//
//        List<ServiceInstance> serviceDiscoveryTestList = DiscoveryClient.getInstances("ServiceDiscoveryTest");
//        ServiceInstance serviceInstance = serviceDiscoveryTestList.get(0);
//        System.out.println(serviceInstance.getUri().toString());
//        //String serviceDiscoveryTest = RestTemplate.getForObject("http://ServiceDiscoveryTest/service", String.class);
//        String serviceDiscoveryTest = RestTemplate.getForObject(serviceInstance.getUri().toString()+"/service", String.class);
//        return  serviceDiscoveryTest;
//    }
//
//    @GetMapping("ins")
//    public List<String> GetInstances(){
//
//        NamingService naming = null;
//        try {
//            naming = NamingFactory.createNamingService("1.117.193.193:8848");
//            naming.registerInstance("testins", "192.168.31.119", 8888, "TEST1");
//            naming.registerInstance("testins", "192.168.31.119", 9999, "TEST1");
//        } catch (NacosException e) {
//            e.printStackTrace();
//        }
//
//
//        List<ServiceInstance> serviceDiscoveryList = DiscoveryClient.getInstances("testins");
//        List<String> list =new ArrayList<>();
//        for (ServiceInstance serviceInstance : serviceDiscoveryList) {
//            list.add(serviceInstance.getUri().toString());
//        }
//        return  list;
//    }
//
//}
